<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>src\admin\controller\code.js</title>
  
    <link rel="stylesheet" href="../assets/vendor/prettify/prettify-min.css">
    <link rel="stylesheet" href="../assets/css/main.css" id="site_styles">
    <link rel="stylesheet" href="../assets/vendor/bootstrap/css/bootstrap.min.css">
    <link rel="shortcut icon" type="image/png" href="../assets/favicon.png">
</head>
<body class="yui3-smart">
 <nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
        <div class="container-fluid">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
               <a class="navbar-brand mainlogo" href="/static/doc/index.html">
             
            <img alt="" src="../assets/css/logo.png" title="">
            
                
          </a>
            </div>
            <div id="navbar" class="navbar-collapse collapse">
                 <ul class="nav navbar-nav">
                    
                    <li><a href="/home/index/index">首页</a>
                    </li>
                    
                    <li><a href="/static/doc/index.html">文档</a>
                    </li>
                    
                    <li><a href="/admin/index/index">演示</a>
                    </li>
                    
                    <li><a href="/home/index/log">日志</a>
                    </li>
                    
                </ul>
               <div class="navbar-form navbar-right filterAPi" autocomplete="off">
                <input type="text" id='txtSearchAPI' class="form-control search-query" placeholder="Search for API" />
                 <ul id="filterList" class="filterItems dropdown-menu" role="menu"></ul>
                </div>
            </div>
        </div>
    </nav>
    <div id="sidebar">
    <h3>Modules/Classes</h3>
        <div id="api-tabview-filter">
            <input id='txtSearch' type="search" class="form-control" placeholder="Type to filter Modules/Classes">
        </div>
        <dl id="sidebar_list">
             
                <dt>
                    <span class="glyphicon glyphicon-minus"></span>
                    <a href="../modules/admin.controller.html">admin.controller</a>
                </dt>
                <dd>
                    <ul>
                   
                       <li>
                            
                           <a href="../classes/admin.controller.base.html">admin.controller.base</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/admin.controller.code.html">admin.controller.code</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/admin.controller.index.html">admin.controller.index</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/admin.controller.mob.html">admin.controller.mob</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                    </ul>
                </dd>
             
                <dt>
                    <span class="glyphicon glyphicon-minus"></span>
                    <a href="../modules/admin.model.html">admin.model</a>
                </dt>
                <dd>
                    <ul>
                   
                       <li>
                            
                           <a href="../classes/admin.model.code.html">admin.model.code</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/admin.model.code_list.html">admin.model.code_list</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/admin.model.code_lookup.html">admin.model.code_lookup</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/admin.model.groupuser.html">admin.model.groupuser</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/admin.model.groupuser_add.html">admin.model.groupuser_add</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/admin.model.log.html">admin.model.log</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/admin.model.login.html">admin.model.login</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/admin.model.privilege.html">admin.model.privilege</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/admin.model.teamuser.html">admin.model.teamuser</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/admin.model.teamuser_add.html">admin.model.teamuser_add</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/admin.model.user.html">admin.model.user</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                    </ul>
                </dd>
             
                <dt>
                    <span class="glyphicon glyphicon-minus"></span>
                    <a href="../modules/cmpage.controller.html">cmpage.controller</a>
                </dt>
                <dd>
                    <ul>
                   
                       <li>
                            
                           <a href="../classes/cmpage.controller.base.html">cmpage.controller.base</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/cmpage.controller.mob.html">cmpage.controller.mob</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/cmpage.controller.module.html">cmpage.controller.module</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/cmpage.controller.page.html">cmpage.controller.page</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/cmpage.controller.utils.html">cmpage.controller.utils</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                    </ul>
                </dd>
             
                <dt>
                    <span class="glyphicon glyphicon-minus"></span>
                    <a href="../modules/cmpage.logic.html">cmpage.logic</a>
                </dt>
                <dd>
                    <ul>
                   
                       <li>
                            
                           <a href="../classes/cmpage.logic.page.html">cmpage.logic.page</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                    </ul>
                </dd>
             
                <dt>
                    <span class="glyphicon glyphicon-minus"></span>
                    <a href="../modules/cmpage.model.html">cmpage.model</a>
                </dt>
                <dd>
                    <ul>
                   
                       <li>
                            
                           <a href="../classes/cmpage.model.area.html">cmpage.model.area</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/cmpage.model.base.html">cmpage.model.base</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/cmpage.model.file_list.html">cmpage.model.file_list</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/cmpage.model.page.html">cmpage.model.page</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/cmpage.model.page_excel.html">cmpage.model.page_excel</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/cmpage.model.page_lookup.html">cmpage.model.page_lookup</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/cmpage.model.page_mob.html">cmpage.model.page_mob</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/cmpage.model.utils.html">cmpage.model.utils</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/cmpage.cmpage_global.html">cmpage.cmpage_global</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/cmpage.cmpage_global_flow.html">cmpage.cmpage_global_flow</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                    </ul>
                </dd>
             
                <dt>
                    <span class="glyphicon glyphicon-minus"></span>
                    <a href="../modules/demo.model.html">demo.model</a>
                </dt>
                <dd>
                    <ul>
                   
                       <li>
                            
                           <a href="../classes/flow.model.proc_assign.html">flow.model.proc_assign</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/cmpage.model.appr.html">cmpage.model.appr</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/flow.model.proc.html">flow.model.proc</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/flow.model.task.html">flow.model.task</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/flow.model.task_act.html">flow.model.task_act</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/flow.model.task_act_appr.html">flow.model.task_act_appr</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                    </ul>
                </dd>
             
                <dt>
                    <span class="glyphicon glyphicon-minus"></span>
                    <a href="../modules/flow.controller.html">flow.controller</a>
                </dt>
                <dd>
                    <ul>
                   
                       <li>
                            
                           <a href="../classes/flow.controller.act.html">flow.controller.act</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/flow.controller.base.html">flow.controller.base</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/flow.controller.proc.html">flow.controller.proc</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/flow.controller.task.html">flow.controller.task</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/flow.controller.task_act.html">flow.controller.task_act</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                    </ul>
                </dd>
             
                <dt>
                    <span class="glyphicon glyphicon-minus"></span>
                    <a href="../modules/flow.model.html">flow.model</a>
                </dt>
                <dd>
                    <ul>
                   
                       <li>
                            
                           <a href="../classes/flow.model.act.html">flow.model.act</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/flow.model.act_path.html">flow.model.act_path</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                    </ul>
                </dd>
             
        </dl>
</div>
   
    <div class="stdoc-content">
        <!--     <form id="options-form" class="form-inline pull-right">
        Show:
        <label for="api-show-inherited" class="checkbox">
            <input type="checkbox" id="api-show-inherited" checked>
            Inherited
        </label>

        <label for="api-show-protected" class="checkbox">
            <input type="checkbox" id="api-show-protected">
            Protected
        </label>

        <label for="api-show-private" class="checkbox">
            <input type="checkbox" id="api-show-private">
            Private
        </label>
        <label for="api-show-deprecated" class="checkbox">
            <input type="checkbox" id="api-show-deprecated">
            Deprecated
        </label>

    </form>

 -->
        <div class="apidocs">
            <div id="docs-main">
                <div class="content">
                    <div class="page-header">
    <h1>src\admin\controller\code.js <small>File</small></h1>
</div>

<div class="file">
    <pre class="prettyprint linenums" id='src_code'>
&#x27;use strict&#x27;;
// +----------------------------------------------------------------------
// | CmPage [ 通用页面框架 ]
// +----------------------------------------------------------------------
// | Licensed under the Apache License, Version 2.0
// +----------------------------------------------------------------------
// | Author: defans &lt;defans@sina.cn&gt;
// +----------------------------------------------------------------------
/**
 @module admin.controller
 */

/**
 * 代码与参数模块的RUL接口，包括常用参数设置、权限相关配置
 * @class admin.controller.code
 */
import Base from &#x27;./base.js&#x27;;

export default class extends Base {
    /**
     * 取代码树，输入根节点ID为参数 &lt;br/&gt;
     * 点击某个节点，右侧显示其子节点列表，增删改后更新左侧树 &lt;br/&gt;
     * RUL调用如：/admin/code_tree?rootid=1 &lt;br/&gt;
     * @method codeTree
     * @return {promise}   代码树页面
     */
  async codeTreeAction(){
    let vb={};
    vb.rootID=this.http.get(&#x27;rootid&#x27;);
    vb.treeID=&#x60;codeTree${vb.rootID}&#x60;;
    let model = this.model(&#x27;code&#x27;);
    vb.list =await model.getTreeList(vb.rootID,true);
//    cmpage.debug(JSON.stringify(vb));
    this.assign(&#x27;vb&#x27;,vb);
    return this.display();
  }

    /**
     * 参数选择，查找带回页面，输入根节点ID为参数 &lt;br/&gt;
     * 点击某个节点，右侧显示其子节点列表，选择后返回 &lt;br/&gt;
     * RUL调用如：/admin/code/code_lookup?rootid=1185*multiselect=false &lt;br/&gt;
     * @method codeLookup
     * @return {promise}   参数选择页面
     */
    async codeLookupAction(){
        let vb={};
        vb.rootID=this.http.get(&#x27;rootid&#x27;);
        vb.treeID=&#x60;codeTree${vb.rootID}&#x60;;
        let model = this.model(&#x27;code&#x27;);
        vb.list =await model.getTreeList(vb.rootID,true);
//    cmpage.debug(JSON.stringify(vb));
        this.assign(&#x27;vb&#x27;,vb);
        return this.display();
    }

    /**
     * 账套用户设置的主界面
     * @method groupUserMain
     * @return {json}
     */
  async groupUserMainAction(){
    let model = this.model(&#x27;code&#x27;);
    let treeList =await model.getTreeList(2,true);
    this.assign(&#x27;treeList&#x27;,treeList);
    return this.display();
  }

    /**
     * 增加某帐套的用户
     * @method groupUserAdd
     * @return {json}
     */
    async groupUserAddAction(){
        let groupID = this.get(&#x27;groupID&#x27;);
        let userIds = this.get(&#x27;userIds&#x27;).split(&#x27;,&#x27;);
        for(let userID of userIds){
            await this.model(&#x27;t_group_user&#x27;).add({c_group:groupID, c_user:userID});
        }
        return this.json({statusCode:200,message:&#x27;用户加入成功!&#x27;});
    }
    /**
     * 删除某帐套的用户
     * @method groupUserDel
     * @return {json}
     */
    async groupUserDelAction(){
        await this.model(&#x27;t_group_user&#x27;).where(&#x60; id in(${this.get(&#x27;ids&#x27;)})&#x60;).delete();
        return this.json({statusCode:200,message:&#x27;用户删除成功!&#x27;});
    }

    /**
     * 团队用户设置的主界面
     * @method teamUserMain
     * @return {json}
     */
    async teamUserMainAction(){
        let model = this.model(&#x27;code&#x27;);
        let treeList =await model.getTreeList(7,true);
        this.assign(&#x27;treeList&#x27;,treeList);
        return this.display();
    }

    /**
     * 增加某团队的用户
     * @method teamUserAdd
     * @return {json}
     */
    async teamUserAddAction(){
        let teamID = this.get(&#x27;teamID&#x27;);
        let userIds = this.get(&#x27;userIds&#x27;).split(&#x27;,&#x27;);
        for(let userID of userIds){
            await this.model(&#x27;t_team_user&#x27;).add({c_team:teamID, c_user:userID});
        }
        return this.json({statusCode:200,message:&#x27;用户加入成功!&#x27;});
    }
    /**
     * 删除某团队的用户
     * @method teamUserDel
     * @return {json}
     */
    async teamUserDelAction(){
        await this.model(&#x27;t_team_user&#x27;).where(&#x60; id in(${this.get(&#x27;ids&#x27;)})&#x60;).delete();
        return this.json({statusCode:200,message:&#x27;用户删除成功!&#x27;});
    }

    /**
     * 角色权限设置主界面
     * @method rolePrivilege
     * @return {json}
     */
  async rolePrivilegeAction(){
    let model = this.model(&#x27;code&#x27;);
    let treeList =await model.getTreeList(3,true);
//    cmpage.debug(JSON.stringify(vb));
    this.assign(&#x27;treeList&#x27;,treeList);
    return this.display();
  }

    /**
     * 某个角色的权限集合展示，树状结构
     * @method roleGetPrivilegeTree
     * @return {json}
     */
  async roleGetPrivilegeTreeAction(){
    let roleID = this.http.post(&#x27;roleID&#x27;);
    let treeList =await this.model(&#x27;privilege&#x27;).roleGetPrivilegeTree(roleID);
//    cmpage.debug(JSON.stringify(vb));
    return this.json(treeList);
  }

    /**
     * 保存某个角色的权限设置
     * @method roleSavePrivilege
     * @return {json}
     */
  async roleSavePrivilegeAction(){
    let parms =this.http.post();
    //cmpage.debug(rec);
    await this.model(&#x27;privilege&#x27;).roleSavePrivilege(parms);
    return this.json({statusCode:200,message:&#x27;保存成功!&#x27;,data:{}});
  }

    /**
     * 某个用户的权限集合展示，树状结构
     * @method userGetPrivilegeTree
     * @return {json}
     */
    async userGetPrivilegeTreeAction(){
        let user = await this.session(&#x27;user&#x27;);
        let parms = this.http.get();
        if(!think.isEmpty(parms.userID)){
            user = await this.model(&#x27;user&#x27;).getUserById(parms.userID);
        }
        let isMine = !think.isEmpty(parms.isMine);
        let treeList =await this.model(&#x27;privilege&#x27;).userGetPrivilegeTree(user.id, user.c_role, 1);
//    cmpage.debug(JSON.stringify(vb));
        this.assign(&#x27;treeList&#x27;,treeList);
        this.assign(&#x27;vb&#x27;,{userID:user.id, isMine:isMine});
        return this.display();
    }

    /**
     * 保存某个用户的定制权限设置
     * @method userSavePrivilege
     * @return {json}
     */
    async userSavePrivilegeAction(){
        let parms =this.http.post();
        //cmpage.debug(rec);
        await this.model(&#x27;privilege&#x27;).userSavePrivilege(parms);
        return this.json({statusCode:200,message:&#x27;保存成功!&#x27;,data:{}});
    }

    /**
     * 保存某个用户的定制权限设置
     * @method userSavePrivilege
     * @return {json}
     */
    async userSetPwdInitAction(){
        let userID =this.http.get(&#x27;userID&#x27;);
        if(think.isEmpty(userID)){
            return this.json({statusCode:300, message:&#x27;用户ID无效！&#x27;});
        }
        await this.model(&#x27;t_user&#x27;).where({id:userID}).update({c_login_pwd:think.md5(&#x27;123456&#x27;)});
        await this.cache(&quot;users&quot;,null);  //清除users缓存
        return this.json({statusCode:200, message:&#x27;密码已修改修改为初始密码（123456）！&#x27;});
    }


    /**
     * 代码树，输入根节点ID为参数 ------- 以下3个操作已废弃，改用 codeTreeAction -----------
     * 直接通过树增删改节点
     * /admin/code?rootid=1
     */
    async codeAction(){
        let vb={};
        vb.rootID=this.http.get(&#x27;rootid&#x27;);
        vb.treeID=&#x60;code${vb.rootID}&#x60;;
        let model = this.model(&#x27;code&#x27;);
        vb.list =await model.getTreeList(vb.rootID,true);
        // cmpage.debug(JSON.stringify(vb));
        this.assign(&#x27;vb&#x27;,vb);
        return this.display();
    }

    async codeSaveAction(){
        let ret={statusCode:200,message:&#x27;&#x27;,data:{}};
        let parms =this.http.post();
        //cmpage.debug(rec);

        let model = this.model(&#x27;t_code&#x27;);
        if(parms.id ==0){
            let rec={};
            Object.keys(parms).map(key=&gt;{if(key !=&#x27;id&#x27;){
                rec[key] =parms[key];
            }});
            ret.data.id =await model.add(rec);
            cmpage.debug(JSON.stringify(ret));
        }else if(parms.id &gt;0){
            ret.data.id =parseInt(parms.id);
            await model.where({id: ret.data.id}).update(parms);
        }

        await this.model(&#x27;code&#x27;).clearCodeCache();
        return this.json(ret);
    }

    async codeDelAction(){
        let ret={statusCode:200,message:&#x27;&#x27;,data:{}};
        let parms =this.http.post();
        //cmpage.debug(rec);

        let model = this.model(&#x27;t_code&#x27;);
        if(parms.id &gt;0){
            await model.where({id: parms.id}).delete();
        }
        return this.json(ret);
    }

    ztreeAction(){
        return this.display();
    }
}

    </pre>
</div>

                </div>
            </div>
        </div>
    </div>
<a id="gotoTop" class='well well-small' href='#'>
    Top
</a>
<script src="../assets/vendor/jquery/jquery-1.8.2.min.js"></script>
<script src="../assets/vendor/bootstrap/js/bootstrap.min.js"></script>
<script src="../assets/vendor/prettify/prettify-min.js"></script>
<script src="../assets/js/config.js"></script>
<script src="../assets/js/doc.js"></script>
</body>
</html>
